package com.itheima.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.github.pagehelper.Page;
import com.itheima.pojo.Emp;
import com.itheima.pojo.LoginInfo;
import com.itheima.pojo.OperateLog;
import com.itheima.pojo.Result;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper extends BaseMapper<Emp> {
//    @Select("select count(*) from emp left join dept on emp.dept_id = dept.id")
//    public abstract long getTotal();
//
//    @Select("select emp.* , dept.name as deptName from emp left join dept on emp.dept_id = dept.id limit #{index} , #{pageSize} ")
//    public abstract List<Emp> getRows(@Param("index") Integer index, @Param("pageSize") Integer pageSize);
    //@Select("select emp.* , dept.name as deptName from emp left join dept on emp.dept_id = dept.id ")
    public List<Emp> findAll(@Param("name") String name , @Param("gender") Integer gender , @Param("begin")LocalDate begin ,
                             @Param("end")LocalDate end);

    @Insert("insert  into emp (username , name , gender , phone , job , salary , image , entry_date , dept_id , create_time , update_time ) " +
            "values (#{username} , #{name} , #{gender} , #{phone} , #{job} , #{salary} , #{image} ,#{entryDate} , #{deptId} , #{createTime} , #{updateTime})")
    @Options(useGeneratedKeys = true , keyProperty = "id") //添加数据回填到emp对象中的id成员变量上
    public abstract  void insertEmp(Emp emp);
    //删
    public abstract void deleteEmp(@Param("ids") List<Integer> ids);
    //数据回显
    public abstract Emp getById(Integer id);
    //更新后的数据
    void updateEmp(Emp emp);
    //树状
    List<Map<String, Object>> calcJobCount();

    List<Map<String , Object>> getEmpGenderData();
    @Select("select emp.* from emp ")
    List<Emp> queryAllEmp();

    @Select("select * from emp where username = #{username} and password = #{password}")
    LoginInfo login(Emp emp);

    @Select("select operate_Log.* ,emp.name as operateEmpName  from operate_Log left join emp on emp.id = operate_Log.operate_emp_id  ")
    List<OperateLog> getLog();


}
